﻿using System;
using System.Collections;
using System.Collections.Generic;
using static Enums.Split;

public static partial class Utility
{

    /// <summary>
    /// 分割工具库
    /// </summary>
    public static class Split
    {

        public static string[] SplitStr(string str, Mode mode)
        {
            return null;
        }

        
        public static int GetSplitCount(string str, char sp)
        {
            int ret = 0;
            int idx = 0;
            while (idx < str.Length)
            {
                var idx2 = str.IndexOf(sp, idx);
                if (idx2 < 0)
                    break;
                ret += 1;
                idx = idx2 + 1;
            }
            return ret + 1;
        }

        public static IEnumerable<string> GameSplit(string str, char sp)
        {
            int idx = 0;
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == sp)
                {
                    yield return str.Substring(idx, i - idx);
                    idx = i + 1;
                }
            }
            if (idx == 0)
                yield return str;
            else
                yield return str.Substring(idx);
        }

        public static IEnumerable<string> GameSplit(string str, string sp)
        {
            int idx = 0, nextIdx;
            while ((nextIdx = str.IndexOf(sp, idx)) > -1)
            {
                yield return str.Substring(idx, nextIdx - idx);
                idx = nextIdx + 1;
            }
            if (idx == 0)
                yield return str;
            else
                yield return str.Substring(idx);
        }
    }
}
